package io.renren.modules.biz.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.Assert;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.biz.entity.CenterEntity;
import io.renren.modules.biz.service.CenterService;

import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

/**
 * 游戏大厅
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-09-03 14:51:31
 */
@RestController
@RequestMapping("biz/center")
public class CenterController {
	@Autowired
	private CenterService centerService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("biz:center:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = centerService.queryPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("biz:center:info")
	public R info(@PathVariable("id") Long id) {
		CenterEntity center = centerService.selectById(id);

		return R.ok().put("center", center);
	}

	/**
	 * 保存
	 */
	@SysLog("添加大厅")
	@RequestMapping("/save")
	@RequiresPermissions("biz:center:save")
	public R save(@RequestBody CenterEntity center) {
		ValidatorUtils.validateEntity(center);
		center.setCreateTime(new Date());
		centerService.insert(center);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@SysLog("大厅修改")
	@RequestMapping("/update")
	@RequiresPermissions("biz:center:update")
	public R update(@RequestBody CenterEntity center) {
		ValidatorUtils.validateEntity(center);
		centerService.updateById(center);

		return R.ok();
	}

	/**
	 * 启用/禁用
	 */
	@SysLog("大厅启用/禁用")
	@RequestMapping("/changeStatus")
	@RequiresPermissions("biz:center:update")
	public R changeStatus(Integer status, Long[] ids) {
		Assert.notNull(status, "参数异常[status]");
		Assert.notNull(ids, "machineIds is null");
		Assert.noNullElements(ids, "参数异常[machineIds]");
		CenterEntity entity = new CenterEntity();
		entity.setStatus(status);
		centerService.update(entity, new EntityWrapper<CenterEntity>().in("id", ids));

		return R.ok();
	}

}
